home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / perl-5.003-complete / bin / s2p < prev   
Text File  |  1996-09-09  |  14KB  |  759 lines

  1. #!/ade/bin/perl
  2.  
  3. eval 'exec /ade/bin/perl -S $0 ${1+"$@"}'
  4.     if $running_under_some_shell;
  5.  
  6. $bin = '/ade/bin';
  7.  
  8. # $RCSfile: s2p.SH,v $$Revision: 4.0.1.2 $$Date: 92/06/08 17:26:31 $
  9. #
  10. # $Log:    s2p.SH,v $
  11. # Revision 4.0.1.2  92/06/08  17:26:31  lwall
  12. # patch20: s2p didn't output portable startup code
  13. # patch20: added ... as variant on ..
  14. # patch20: s2p didn't translate s/pat/\&/ or s/pat/\$/ or s/pat/\\1/ right
  15. # Revision 4.0.1.1  91/06/07  12:19:18  lwall
  16. # patch4: s2p now handles embedded newlines better and optimizes common idioms
  17. # Revision 4.0  91/03/20  01:57:59  lwall
  18. # 4.0 baseline.
  19. #
  20.  
  21. $indent = 4;
  22. $shiftwidth = 4;
  23. $l = '{'; $r = '}';
  24.  
  25. while ($ARGV[0] =~ /^-/) {
  26.     $_ = shift;
  27.   last if /^--/;
  28.     if (/^-D/) {
  29.     $debug++;
  30.     open(BODY,'>-');
  31.     next;
  32.     }
  33.     if (/^-n/) {
  34.     $assumen++;
  35.     next;
  36.     }
  37.     if (/^-p/) {
  38.     $assumep++;
  39.     next;
  40.     }
  41.     die "I don't recognize this switch: $_\n";
  42. }
  43.  
  44. unless ($debug) {
  45.     open(BODY,">/tmp/sperl$$") ||
  46.       &Die("Can't open temp file: $!\n");
  47. }
  48.  
  49. if (!$assumen && !$assumep) {
  50.     print BODY &q(<<'EOT');
  51. :    while ($ARGV[0] =~ /^-/) {
  52. :        $_ = shift;
  53. :      last if /^--/;
  54. :        if (/^-n/) {
  55. :        $nflag++;
  56. :        next;
  57. :        }
  58. :        die "I don't recognize this switch: $_\\n";
  59. :    }
  60. :    
  61. EOT
  62. }
  63.  
  64. print BODY &q(<<'EOT');
  65. :    #ifdef PRINTIT
  66. :    #ifdef ASSUMEP
  67. :    $printit++;
  68. :    #else
  69. :    $printit++ unless $nflag;
  70. :    #endif
  71. :    #endif
  72. :    <><>
  73. :    $\ = "\n";        # automatically add newline on print
  74. :    <><>
  75. :    #ifdef TOPLABEL
  76. :    LINE:
  77. :    while (chop($_ = <>)) {
  78. :    #else
  79. :    LINE:
  80. :    while (<>) {
  81. :        chop;
  82. :    #endif
  83. EOT
  84.  
  85. LINE:
  86. while (<>) {
  87.  
  88.     # Wipe out surrounding whitespace.
  89.  
  90.     s/[ \t]*(.*)\n$/$1/;
  91.  
  92.     # Perhaps it's a label/comment.
  93.  
  94.     if (/^:/) {
  95.     s/^:[ \t]*//;
  96.     $label = &make_label($_);
  97.     if ($. == 1) {
  98.         $toplabel = $label;
  99.         if (/^(top|(re)?start|redo|begin(ning)|again|input)$/i) {
  100.         $_ = <>;
  101.         redo LINE; # Never referenced, so delete it if not a comment.
  102.         }
  103.     }
  104.     $_ = "$label:";
  105.     if ($lastlinewaslabel++) {
  106.         $indent += 4;
  107.         print BODY &tab, ";\n";
  108.         $indent -= 4;
  109.     }
  110.     if ($indent >= 2) {
  111.         $indent -= 2;
  112.         $indmod = 2;
  113.     }
  114.     next;
  115.     } else {
  116.     $lastlinewaslabel = '';
  117.     }
  118.  
  119.     # Look for one or two address clauses
  120.  
  121.     $addr1 = '';
  122.     $addr2 = '';
  123.     if (s/^([0-9]+)//) {
  124.     $addr1 = "$1";
  125.     $addr1 = "\$. == $addr1" unless /^,/;
  126.     }
  127.     elsif (s/^\$//) {
  128.     $addr1 = 'eof()';
  129.     }
  130.     elsif (s|^/||) {
  131.     $addr1 = &fetchpat('/');
  132.     }
  133.     if (s/^,//) {
  134.     if (s/^([0-9]+)//) {
  135.         $addr2 = "$1";
  136.     } elsif (s/^\$//) {
  137.         $addr2 = "eof()";
  138.     } elsif (s|^/||) {
  139.         $addr2 = &fetchpat('/');
  140.     } else {
  141.         &Die("Invalid second address at line $.\n");
  142.     }
  143.     if ($addr2 =~ /^\d+$/) {
  144.         $addr1 .= "..$addr2";
  145.     }
  146.     else {
  147.         $addr1 .= "...$addr2";
  148.     }
  149.     }
  150.  
  151.     # Now we check for metacommands {, }, and ! and worry
  152.     # about indentation.
  153.  
  154.     s/^[ \t]+//;
  155.     # a { to keep vi happy
  156.     if ($_ eq '}') {
  157.     $indent -= 4;
  158.     next;
  159.     }
  160.     if (s/^!//) {
  161.     $if = 'unless';
  162.     $else = "$r else $l\n";
  163.     } else {
  164.     $if = 'if';
  165.     $else = '';
  166.     }
  167.     if (s/^{//) {    # a } to keep vi happy
  168.     $indmod = 4;
  169.     $redo = $_;
  170.     $_ = '';
  171.     $rmaybe = '';
  172.     } else {
  173.     $rmaybe = "\n$r";
  174.     if ($addr2 || $addr1) {
  175.         $space = ' ' x $shiftwidth;
  176.     } else {
  177.         $space = '';
  178.     }
  179.     $_ = &transmogrify();
  180.     }
  181.  
  182.     # See if we can optimize to modifier form.
  183.  
  184.     if ($addr1) {
  185.     if ($_ !~ /[\n{}]/ && $rmaybe && !$change &&
  186.       $_ !~ / if / && $_ !~ / unless /) {
  187.         s/;$/ $if $addr1;/;
  188.         $_ = substr($_,$shiftwidth,1000);
  189.     } else {
  190.         $_ = "$if ($addr1) $l\n$change$_$rmaybe";
  191.     }
  192.     $change = '';
  193.     next LINE;
  194.     }
  195. } continue {
  196.     @lines = split(/\n/,$_);
  197.     for (@lines) {
  198.     unless (s/^ *<<--//) {
  199.         print BODY &tab;
  200.     }
  201.     print BODY $_, "\n";
  202.     }
  203.     $indent += $indmod;
  204.     $indmod = 0;
  205.     if ($redo) {
  206.     $_ = $redo;
  207.     $redo = '';
  208.     redo LINE;
  209.     }
  210. }
  211. if ($lastlinewaslabel++) {
  212.     $indent += 4;
  213.     print BODY &tab, ";\n";
  214.     $indent -= 4;
  215. }
  216.  
  217. if ($appendseen || $tseen || !$assumen) {
  218.     $printit++ if $dseen || (!$assumen && !$assumep);
  219.     print BODY &q(<<'EOT');
  220. :    #ifdef SAWNEXT
  221. :    }
  222. :    continue {
  223. :    #endif
  224. :    #ifdef PRINTIT
  225. :    #ifdef DSEEN
  226. :    #ifdef ASSUMEP
  227. :        print if $printit++;
  228. :    #else
  229. :        if ($printit)
  230. :        { print; }
  231. :        else
  232. :        { $printit++ unless $nflag; }
  233. :    #endif
  234. :    #else
  235. :        print if $printit;
  236. :    #endif
  237. :    #else
  238. :        print;
  239. :    #endif
  240. :    #ifdef TSEEN
  241. :        $tflag = 0;
  242. :    #endif
  243. :    #ifdef APPENDSEEN
  244. :        if ($atext) { chop $atext; print $atext; $atext = ''; }
  245. :    #endif
  246. EOT
  247.  
  248. print BODY &q(<<'EOT');
  249. :    }
  250. EOT
  251. }
  252.  
  253. close BODY;
  254.  
  255. unless ($debug) {
  256.     open(HEAD,">/tmp/sperl2$$.c")
  257.       || &Die("Can't open temp file 2: $!\n");
  258.     print HEAD "#define PRINTIT\n"    if $printit;
  259.     print HEAD "#define APPENDSEEN\n"    if $appendseen;
  260.     print HEAD "#define TSEEN\n"    if $tseen;
  261.     print HEAD "#define DSEEN\n"    if $dseen;
  262.     print HEAD "#define ASSUMEN\n"    if $assumen;
  263.     print HEAD "#define ASSUMEP\n"    if $assumep;
  264.     print HEAD "#define TOPLABEL\n"    if $toplabel;
  265.     print HEAD "#define SAWNEXT\n"    if $sawnext;
  266.     if ($opens) {print HEAD "$opens\n";}
  267.     open(BODY,"/tmp/sperl$$")
  268.       || &Die("Can't reopen temp file: $!\n");
  269.     while (<BODY>) {
  270.     print HEAD $_;
  271.     }
  272.     close HEAD;
  273.  
  274.     print &q(<<"EOT");
  275. :    #!$bin/perl
  276. :    eval 'exec $bin/perl -S \$0 \${1+"\$@"}'
  277. :        if \$running_under_some_shell;
  278. :    
  279. EOT
  280.     open(BODY,"cc -E /tmp/sperl2$$.c |") ||
  281.     &Die("Can't reopen temp file: $!\n");
  282.     while (<BODY>) {
  283.     /^# [0-9]/ && next;
  284.     /^[ \t]*$/ && next;
  285.     s/^<><>//;
  286.     print;
  287.     }
  288. }
  289.  
  290. &Cleanup;
  291. exit;
  292.  
  293. sub Cleanup {
  294.     chdir "/tmp";
  295.     unlink "sperl$$", "sperl2$$", "sperl2$$.c";
  296. }
  297. sub Die {
  298.     &Cleanup;
  299.     die $_[0];
  300. }
  301. sub tab {
  302.     "\t" x ($indent / 8) . ' ' x ($indent % 8);
  303. }
  304. sub make_filehandle {
  305.     local($_) = $_[0];
  306.     local($fname) = $_;
  307.     if (!$seen{$fname}) {
  308.     $_ = "FH_" . $_ if /^\d/;
  309.     s/[^a-zA-Z0-9]/_/g;
  310.     s/^_*//;
  311.     $_ = "\U$_";
  312.     if ($fhseen{$_}) {
  313.         for ($tmp = "a"; $fhseen{"$_$tmp"}; $a++) {}
  314.         $_ .= $tmp;
  315.     }
  316.     $fhseen{$_} = 1;
  317.     $opens .= &q(<<"EOT");
  318. :    open($_, '>$fname') || die "Can't create $fname: \$!";
  319. EOT
  320.     $seen{$fname} = $_;
  321.     }
  322.     $seen{$fname};
  323. }
  324.  
  325. sub make_label {
  326.     local($label) = @_;
  327.     $label =~ s/[^a-zA-Z0-9]/_/g;
  328.     if ($label =~ /^[0-9_]/) { $label = 'L' . $label; }
  329.     $label = substr($label,0,8);
  330.  
  331.     # Could be a reserved word, so capitalize it.
  332.     substr($label,0,1) =~ y/a-z/A-Z/
  333.       if $label =~ /^[a-z]/;
  334.  
  335.     $label;
  336. }
  337.  
  338. sub transmogrify {
  339.     {    # case
  340.     if (/^d/) {
  341.         $dseen++;
  342.         chop($_ = &q(<<'EOT'));
  343. :    <<--#ifdef PRINTIT
  344. :    $printit = 0;
  345. :    <<--#endif
  346. :    next LINE;
  347. EOT
  348.         $sawnext++;
  349.         next;
  350.     }
  351.  
  352.     if (/^n/) {
  353.         chop($_ = &q(<<'EOT'));
  354. :    <<--#ifdef PRINTIT
  355. :    <<--#ifdef DSEEN
  356. :    <<--#ifdef ASSUMEP
  357. :    print if $printit++;
  358. :    <<--#else
  359. :    if ($printit)
  360. :        { print; }
  361. :    else
  362. :        { $printit++ unless $nflag; }
  363. :    <<--#endif
  364. :    <<--#else
  365. :    print if $printit;
  366. :    <<--#endif
  367. :    <<--#else
  368. :    print;
  369. :    <<--#endif
  370. :    <<--#ifdef APPENDSEEN
  371. :    if ($atext) {chop $atext; print $atext; $atext = '';}
  372. :    <<--#endif
  373. :    $_ = <>;
  374. :    chop;
  375. :    <<--#ifdef TSEEN
  376. :    $tflag = 0;
  377. :    <<--#endif
  378. EOT
  379.         next;
  380.     }
  381.  
  382.     if (/^a/) {
  383.         $appendseen++;
  384.         $command = $space . "\$atext .= <<'End_Of_Text';\n<<--";
  385.         $lastline = 0;
  386.         while (<>) {
  387.         s/^[ \t]*//;
  388.         s/^[\\]//;
  389.         unless (s|\\$||) { $lastline = 1;}
  390.         s/^([ \t]*\n)/<><>$1/;
  391.         $command .= $_;
  392.         $command .= '<<--';
  393.         last if $lastline;
  394.         }
  395.         $_ = $command . "End_Of_Text";
  396.         last;
  397.     }
  398.  
  399.     if (/^[ic]/) {
  400.         if (/^c/) { $change = 1; }
  401.         $addr1 = 1 if $addr1 eq '';
  402.         $addr1 = '$iter = (' . $addr1 . ')';
  403.         $command = $space .
  404.           "    if (\$iter == 1) { print <<'End_Of_Text'; }\n<<--";
  405.         $lastline = 0;
  406.         while (<>) {
  407.         s/^[ \t]*//;
  408.         s/^[\\]//;
  409.         unless (s/\\$//) { $lastline = 1;}
  410.         s/'/\\'/g;
  411.         s/^([ \t]*\n)/<><>$1/;
  412.         $command .= $_;
  413.         $command .= '<<--';
  414.         last if $lastline;
  415.         }
  416.         $_ = $command . "End_Of_Text";
  417.         if ($change) {
  418.         $dseen++;
  419.         $change = "$_\n";
  420.         chop($_ = &q(<<"EOT"));
  421. :    <<--#ifdef PRINTIT
  422. :    $space\$printit = 0;
  423. :    <<--#endif
  424. :    ${space}next LINE;
  425. EOT
  426.         $sawnext++;
  427.         }
  428.         last;
  429.     }
  430.  
  431.     if (/^s/) {
  432.         $delim = substr($_,1,1);
  433.         $len = length($_);
  434.         $repl = $end = 0;
  435.         $inbracket = 0;
  436.         for ($i = 2; $i < $len; $i++) {
  437.         $c = substr($_,$i,1);
  438.         if ($c eq $delim) {
  439.             if ($inbracket) {
  440.             substr($_, $i, 0) = '\\';
  441.             $i++;
  442.             $len++;
  443.             }
  444.             else {
  445.             if ($repl) {
  446.                 $end = $i;
  447.                 last;
  448.             } else {
  449.                 $repl = $i;
  450.             }
  451.             }
  452.         }
  453.         elsif ($c eq '\\') {
  454.             $i++;
  455.             if ($i >= $len) {
  456.             $_ .= 'n';
  457.             $_ .= <>;
  458.             $len = length($_);
  459.             $_ = substr($_,0,--$len);
  460.             }
  461.             elsif (substr($_,$i,1) =~ /^[n]$/) {
  462.             ;
  463.             }
  464.             elsif (!$repl &&
  465.               substr($_,$i,1) =~ /^[(){}\w]$/) {
  466.             $i--;
  467.             $len--;
  468.             substr($_, $i, 1) = '';
  469.             }
  470.             elsif (!$repl &&
  471.               substr($_,$i,1) =~ /^[<>]$/) {
  472.             substr($_,$i,1) = 'b';
  473.             }
  474.             elsif ($repl && substr($_,$i,1) =~ /^\d$/) {
  475.             substr($_,$i-1,1) = '$';
  476.             }
  477.         }
  478.         elsif ($c eq '&' && $repl) {
  479.             substr($_, $i, 0) = '$';
  480.             $i++;
  481.             $len++;
  482.         }
  483.         elsif ($c eq '$' && $repl) {
  484.             substr($_, $i, 0) = '\\';
  485.             $i++;
  486.             $len++;
  487.         }
  488.         elsif ($c eq '[' && !$repl) {
  489.             $i++ if substr($_,$i,1) eq '^';
  490.             $i++ if substr($_,$i,1) eq ']';
  491.             $inbracket = 1;
  492.         }
  493.         elsif ($c eq ']') {
  494.             $inbracket = 0;
  495.         }
  496.         elsif ($c eq "\t") {
  497.             substr($_, $i, 1) = '\\t';
  498.             $i++;
  499.             $len++;
  500.         }
  501.         elsif (!$repl && index("()+",$c) >= 0) {
  502.             substr($_, $i, 0) = '\\';
  503.             $i++;
  504.             $len++;
  505.         }
  506.         }
  507.         &Die("Malformed substitution at line $.\n")
  508.           unless $end;
  509.         $pat = substr($_, 0, $repl + 1);
  510.         $repl = substr($_, $repl+1, $end-$repl-1);
  511.         $end = substr($_, $end + 1, 1000);
  512.         &simplify($pat);
  513.         $dol = '$';
  514.         $subst = "$pat$repl$delim";
  515.         $cmd = '';
  516.         while ($end) {
  517.         if ($end =~ s/^g//) {
  518.             $subst .= 'g';
  519.             next;
  520.         }
  521.         if ($end =~ s/^p//) {
  522.             $cmd .= ' && (print)';
  523.             next;
  524.         }
  525.         if ($end =~ s/^w[ \t]*//) {
  526.             $fh = &make_filehandle($end);
  527.             $cmd .= " && (print $fh \$_)";
  528.             $end = '';
  529.             next;
  530.         }
  531.         &Die("Unrecognized substitution command".
  532.           "($end) at line $.\n");
  533.         }
  534.         chop ($_ = &q(<<"EOT"));
  535. :    <<--#ifdef TSEEN
  536. :    $subst && \$tflag++$cmd;
  537. :    <<--#else
  538. :    $subst$cmd;
  539. :    <<--#endif
  540. EOT
  541.         next;
  542.     }
  543.  
  544.     if (/^p/) {
  545.         $_ = 'print;';
  546.         next;
  547.     }
  548.  
  549.     if (/^w/) {
  550.         s/^w[ \t]*//;
  551.         $fh = &make_filehandle($_);
  552.         $_ = "print $fh \$_;";
  553.         next;
  554.     }
  555.  
  556.     if (/^r/) {
  557.         $appendseen++;
  558.         s/^r[ \t]*//;
  559.         $file = $_;
  560.         $_ = "\$atext .= `cat $file 2>/dev/null`;";
  561.         next;
  562.     }
  563.  
  564.     if (/^P/) {
  565.         $_ = 'print $1 if /^(.*)/;';
  566.         next;
  567.     }
  568.  
  569.     if (/^D/) {
  570.         chop($_ = &q(<<'EOT'));
  571. :    s/^.*\n?//;
  572. :    redo LINE if $_;
  573. :    next LINE;
  574. EOT
  575.         $sawnext++;
  576.         next;
  577.     }
  578.  
  579.     if (/^N/) {
  580.         chop($_ = &q(<<'EOT'));
  581. :    $_ .= "\n";
  582. :    $len1 = length;
  583. :    $_ .= <>;
  584. :    chop if $len1 < length;
  585. :    <<--#ifdef TSEEN
  586. :    $tflag = 0;
  587. :    <<--#endif
  588. EOT
  589.         next;
  590.     }
  591.  
  592.     if (/^h/) {
  593.         $_ = '$hold = $_;';
  594.         next;
  595.     }
  596.  
  597.     if (/^H/) {
  598.         $_ = '$hold .= "\n"; $hold .= $_;';
  599.         next;
  600.     }
  601.  
  602.     if (/^g/) {
  603.         $_ = '$_ = $hold;';
  604.         next;
  605.     }
  606.  
  607.     if (/^G/) {
  608.         $_ = '$_ .= "\n"; $_ .= $hold;';
  609.         next;
  610.     }
  611.  
  612.     if (/^x/) {
  613.         $_ = '($_, $hold) = ($hold, $_);';
  614.         next;
  615.     }
  616.  
  617.     if (/^b$/) {
  618.         $_ = 'next LINE;';
  619.         $sawnext++;
  620.         next;
  621.     }
  622.  
  623.     if (/^b/) {
  624.         s/^b[ \t]*//;
  625.         $lab = &make_label($_);
  626.         if ($lab eq $toplabel) {
  627.         $_ = 'redo LINE;';
  628.         } else {
  629.         $_ = "goto $lab;";
  630.         }
  631.         next;
  632.     }
  633.  
  634.     if (/^t$/) {
  635.         $_ = 'next LINE if $tflag;';
  636.         $sawnext++;
  637.         $tseen++;
  638.         next;
  639.     }
  640.  
  641.     if (/^t/) {
  642.         s/^t[ \t]*//;
  643.         $lab = &make_label($_);
  644.         $_ = q/if ($tflag) {$tflag = 0; /;
  645.         if ($lab eq $toplabel) {
  646.         $_ .= 'redo LINE;}';
  647.         } else {
  648.         $_ .= "goto $lab;}";
  649.         }
  650.         $tseen++;
  651.         next;
  652.     }
  653.  
  654.     if (/^y/) {
  655.         s/abcdefghijklmnopqrstuvwxyz/a-z/g;
  656.         s/ABCDEFGHIJKLMNOPQRSTUVWXYZ/A-Z/g;
  657.         s/abcdef/a-f/g;
  658.         s/ABCDEF/A-F/g;
  659.         s/0123456789/0-9/g;
  660.         s/01234567/0-7/g;
  661.         $_ .= ';';
  662.     }
  663.  
  664.     if (/^=/) {
  665.         $_ = 'print $.;';
  666.         next;
  667.     }
  668.  
  669.     if (/^q/) {
  670.         chop($_ = &q(<<'EOT'));
  671. :    close(ARGV);
  672. :    @ARGV = ();
  673. :    next LINE;
  674. EOT
  675.         $sawnext++;
  676.         next;
  677.     }
  678.     } continue {
  679.     if ($space) {
  680.         s/^/$space/;
  681.         s/(\n)(.)/$1$space$2/g;
  682.     }
  683.     last;
  684.     }
  685.     $_;
  686. }
  687.  
  688. sub fetchpat {
  689.     local($outer) = @_;
  690.     local($addr) = $outer;
  691.     local($inbracket);
  692.     local($prefix,$delim,$ch);
  693.  
  694.     # Process pattern one potential delimiter at a time.
  695.  
  696.     DELIM: while (s#^([^\]+(|)[\\/]*)([]+(|)[\\/])##) {
  697.     $prefix = $1;
  698.     $delim = $2;
  699.     if ($delim eq '\\') {
  700.         s/(.)//;
  701.         $ch = $1;
  702.         $delim = '' if $ch =~ /^[(){}A-Za-mo-z]$/;
  703.         $ch = 'b' if $ch =~ /^[<>]$/;
  704.         $delim .= $ch;
  705.     }
  706.     elsif ($delim eq '[') {
  707.         $inbracket = 1;
  708.         s/^\^// && ($delim .= '^');
  709.         s/^]// && ($delim .= ']');
  710.     }
  711.     elsif ($delim eq ']') {
  712.         $inbracket = 0;
  713.     }
  714.     elsif ($inbracket || $delim ne $outer) {
  715.         $delim = '\\' . $delim;
  716.     }
  717.     $addr .= $prefix;
  718.     $addr .= $delim;
  719.     if ($delim eq $outer && !$inbracket) {
  720.         last DELIM;
  721.     }
  722.     }
  723.     $addr =~ s/\t/\\t/g;
  724.     &simplify($addr);
  725.     $addr;
  726. }
  727.  
  728. sub q {
  729.     local($string) = @_;
  730.     local($*) = 1;
  731.     $string =~ s/^:\t?//g;
  732.     $string;
  733. }
  734.  
  735. sub simplify {
  736.     $_[0] =~ s/_a-za-z0-9/\\w/ig;
  737.     $_[0] =~ s/a-z_a-z0-9/\\w/ig;
  738.     $_[0] =~ s/a-za-z_0-9/\\w/ig;
  739.     $_[0] =~ s/a-za-z0-9_/\\w/ig;
  740.     $_[0] =~ s/_0-9a-za-z/\\w/ig;
  741.     $_[0] =~ s/0-9_a-za-z/\\w/ig;
  742.     $_[0] =~ s/0-9a-z_a-z/\\w/ig;
  743.     $_[0] =~ s/0-9a-za-z_/\\w/ig;
  744.     $_[0] =~ s/\[\\w\]/\\w/g;
  745.     $_[0] =~ s/\[^\\w\]/\\W/g;
  746.     $_[0] =~ s/\[0-9\]/\\d/g;
  747.     $_[0] =~ s/\[^0-9\]/\\D/g;
  748.     $_[0] =~ s/\\d\\d\*/\\d+/g;
  749.     $_[0] =~ s/\\D\\D\*/\\D+/g;
  750.     $_[0] =~ s/\\w\\w\*/\\w+/g;
  751.     $_[0] =~ s/\\t\\t\*/\\t+/g;
  752.     $_[0] =~ s/(\[.[^]]*\])\1\*/$1+/g;
  753.     $_[0] =~ s/([\w\s!@#%^&-=,:;'"])\1\*/$1+/g;
  754. }
  755.  
  756.